<ui:composition xmlns="http://www.w3.org/1999/xhtml"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:f="http://java.sun.com/jsf/core"
	xmlns:ui="http://java.sun.com/jsf/facelets"
	xmlns:rich="http://richfaces.org/rich"
	xmlns:a4j="http://richfaces.org/a4j"
	xmlns:s="http://jboss.com/products/seam/taglib"
	xmlns:o="http://openfaces.org/">

	<rich:modalPanel id="spatialAnalysisPanel" minHeight="580" minWidth="640">
		<f:facet name="header">
			<h:outputText value="#{messages['permit.spatial_analysis']}"/>
		</f:facet>
		
		<f:facet name="controls">
			<h:panelGroup>
				<h:graphicImage value="/img/close.png" styleClass="hidelink"
					id="hideSpatialAnalysisPanel" />
				<rich:componentControl for="spatialAnalysisPanel" attachTo="hideSpatialAnalysisPanel"
					operation="hide" event="onclick" />
			</h:panelGroup>
		</f:facet>
		
		<h:form>
			<table width="90%" align="center" border="0">
				<tr>
					<th style="text-align: left;width: 40%">#{messages['permit.spatial_rulegroup_to_apply']}</th>
					<td>
						<h:selectOneMenu value="#{buildingPermitHelper.ruleGroup}" converter="#{buildingPermitHelper.permitRuleGroupConverter}" style="width: 95%">
							<f:selectItems value="#{buildingPermitHelper.permitRuleGroupItemList}"/>
						</h:selectOneMenu>
					</td>
				</tr>
				<tr>
					<td style="text-align: center" colspan="2">
						<br />
						<a4j:commandButton
							value="Realizar analisis"
							action="#{spatialAnalysisHelper.doNewSpatialAnalysis}"
							reRender="grpSpatialAnalysisPanel">
							<f:setPropertyActionListener target="#{spatialAnalysisHelper.spatialZone}" value="#{buildingPermitHelper.permit.spatialZone}" />
							<f:setPropertyActionListener target="#{spatialAnalysisHelper.ruleGroup}" value="#{buildingPermitHelper.ruleGroup}" />
							<f:setPropertyActionListener target="#{spatialAnalysisHelper.distance}" value="#{null}" />
						</a4j:commandButton>
					</td>
				</tr>
			</table>
		</h:form>
		
		<br />
		
		<h:panelGroup id="grpSpatialAnalysisPanel">
			<rich:panel>
				<div style="height:400px;width:100%;overflow:auto;">
					<ui:include src="/viewer/includes/spatialAnalysisContentIncl.xhtml" />
				</div>
			</rich:panel>
			<br />
			<div align="center">
				<o:commandButton type="button"
					rendered="#{render == null}"
					value="#{messages['button.ok']}"
					onclick="#{rich:component('spatialAnalysisPanel')}.hide();">
				</o:commandButton>
				
				<h:panelGroup>
					<h:form rendered="#{render != null}">
						<table width="30%">
							<tr>
								<td width="50%" align="center">
									<a4j:commandButton
										value="#{messages['button.ok']}"
										reRender="#{render != null ? render : ''}"
										oncomplete="#{rich:component('spatialAnalysisPanel')}.hide();">
										<f:setPropertyActionListener target="#{spatialAnalysisHelper.spatialZone}" value="#{buildingPermitHelper.permit.spatialZone}" />
										<f:setPropertyActionListener target="#{spatialAnalysisHelper.ruleGroup}" value="#{buildingPermitHelper.ruleGroup}" />
										<f:setPropertyActionListener target="#{spatialAnalysisHelper.distance}" value="#{null}" />
									</a4j:commandButton>
								</td>
								<td align="center">
									<o:commandButton type="button"
										value="#{messages['button.close']}"
										onclick="#{rich:component('spatialAnalysisPanel')}.hide();">
									</o:commandButton>
								</td>
							</tr>
						</table>
					</h:form>
				</h:panelGroup>
			</div>
		</h:panelGroup>
	</rich:modalPanel>

</ui:composition>
